package com.smx.dao;

import com.smx.model.entity.Admin;
import com.smx.model.entity.User;
import com.smx.util.DruidUtil;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;

/**
 * @ClassName AdminDao
 * @Description TODO
 * @Author moses
 * @Date 2021/5/9
 **/
public class AdminDao {
    public static Admin findAdmin(Admin admin) {
        Connection conn = DruidUtil.getConnection();
        PreparedStatement state = null;
        ResultSet rs = null;
        try {

            state = conn.prepareStatement("select * from admin where username=? and password =?");
            state.setString(1, admin.getUsername());
            state.setString(2, admin.getPassword());
            rs=state.executeQuery();
            if (rs.next()) {
                admin.setId(rs.getInt("id"));
                admin.setUsername(rs.getString("username"));
                admin.setPassword(rs.getString("password"));
                return admin;
            }
        } catch (SQLException throwables) {
            throwables.printStackTrace();
        }
        finally {
            DruidUtil.close(conn,state,rs);
        }
        return null;
    }
}
